import request from '@/utils/request'
import type {
  ChangePwdByEmailParams,
  ChangePwdParams,
  EmailAndCaptchaParams,
  RegisterPwdParams,
  UserLoginParams,
  VerifyNewEmailParams,
} from './type'
import { AxiosResponse } from 'axios'

// 项目用户相关的请求地址
enum Auth_API {
  POST_BINDING_EMAIL = '/transaction_assistant/auth/binding/email',
  PUT_CHANGE_NEW_EMAIL = '/transaction_assistant/auth/change/newEmail',
  PUT_CHANGE_PWD = '/transaction_assistant/auth/change/pwd',
  PUT_CHANGE_PWD_BYEMAIL = '/transaction_assistant/auth/change/pwd/byEmail',
  POST_PWD_LOGIN = '/transaction_assistant/auth/login/pwd',
  POST_EMAIL_LOGIN = '/transaction_assistant/auth/login/email',
  POST_USER_REGISTER = '/transaction_assistant/auth/register/pwd',
  POST_VERIFY_OLDEMAIL = '/transaction_assistant/auth/verify/oldEmail',
}

/**
 * 绑定邮箱
 * @param {object} params 用户邮箱绑定对象
 * @param {string} params.email 绑定用户邮箱
 * @param {string} params.captcha 验证码
 * @returns
 */
export const reqBindingEmail = (params: EmailAndCaptchaParams) =>
  request.post<any, AxiosResponse<any>>(Auth_API.POST_BINDING_EMAIL, params)

/**
 * 验证并修改邮箱
 * @param {object} params 修改邮箱对象
 * @param {string} params.email 旧邮箱
 * @param {string} params.newEmail 新邮箱
 * @param {string} params.captcha 验证码
 * @returns
 */
export const reqVerifyNewEmail = (params: VerifyNewEmailParams) =>
  request.put<any, AxiosResponse<any>>(Auth_API.PUT_CHANGE_NEW_EMAIL, params)

/**
 * 通过原密码修改密码
 * @param {object} params 修改密码对象
 * @param {string} params.account 用户名
 * @param {string} params.password 旧密码
 * @param {string} params.newPassword 新密码
 * @returns
 */
export const reqChangePwd = (params: ChangePwdParams) =>
  request.put<any, AxiosResponse<any>>(Auth_API.PUT_CHANGE_PWD, params)

/**
 * 通过邮箱修改密码
 * @param {object} params 修改密码对象（email）
 * @param {string} params.email 邮箱
 * @param {string} params.captcha 验证码
 * @param {string} params.newPassword 新密码
 * @returns
 */
export const reqChangePwdByEmail = (params: ChangePwdByEmailParams) =>
  request.put<any, AxiosResponse<any>>(Auth_API.PUT_CHANGE_PWD_BYEMAIL, params)

/**
 * 用户邮箱登录
 * @param {object} params 用户邮箱登录对象
 * @param {string} params.email 登录用户邮箱
 * @param {string} params.captcha 验证码
 * @returns
 */
export const reqUserLoginByEmail = (params: EmailAndCaptchaParams) =>
  request.post<any, AxiosResponse<any>>(Auth_API.POST_EMAIL_LOGIN, params)

/**
 * 用户登录
 * @param {object} params 用户密码登录对象
 * @param {string} params.account 用户名
 * @param {string} params.password 密码
 * @returns
 */
export const reqUserLoginByPwd = (params: UserLoginParams) =>
  request.post<any, AxiosResponse<any>>(Auth_API.POST_PWD_LOGIN, params)

/**
 * 用户注册
 * @param {object} params 用户账号注册录对象
 * @param {string} params.account 用户名
 * @param {string} params.password 密码
 * @param {string} params.resetPassword 密码
 * @returns
 */
export const reqUerRegister = (params: RegisterPwdParams) =>
  request.post<any, AxiosResponse<any>>(Auth_API.POST_USER_REGISTER, params)

/**
 * 验证旧邮箱
 * @param {object} params 用户邮箱登录对象
 * @param {string} params.email 登录用户邮箱
 * @param {string} params.captcha 验证码
 * @returns
 */
export const reqVerifyOldEmail = (params: EmailAndCaptchaParams) =>
  request.post<any, AxiosResponse<any>>(Auth_API.POST_VERIFY_OLDEMAIL, params)
